namespace CISLib
{
    using System;
    using System.Collections;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;

    public class ManageCheckUser
    {
        public static void CopyUserIdToKPI(string label)
        {
            SqlDataReader MyReader = null;
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            string strSQL = "select UserId from TB_SysUser";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            while (MyReader.Read())
            {
                InsertACustomerIdInKPI(MyReader.GetGuid(0), label);
            }
            MyDB.DBClose();
        }

        public static void CopyUserIdToKPIViaRoleId(string label, Guid roleId)
        {
            Province[] provinceAry = ManageProvince.GetAllProvince();
            for (int i = 0; i < provinceAry.Length; i++)
            {
                InsertACustomerIdInKPI_Interface(provinceAry[i].ProvinceId, label);
            }
        }

        public static int GetCompanyCountViaIdInCompanyInfo(Guid userId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            string strSQL = "select count(*) from TB_CompanyInfo where UserId = @UserId";
            MyDB.DBSetSelect(strSQL);
            int result = (int) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return result;
        }

        public static Guid[] GetCompanyIdListInCompanyInfoViaUserId(Guid userId)
        {
            SqlDataReader MyReader = null;
            ArrayList List = new ArrayList();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            string strSQL = "select CompanyId from TB_CompanyInfo where UserId=@UserId";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            while (MyReader.Read())
            {
                Guid id = (Guid) MyReader[0];
                List.Add(id);
            }
            MyDB.DBClose();
            return (Guid[]) List.ToArray(typeof(Guid));
        }

        public static Guid[] GetCompanyIdViaCatIdAndProvinceId(Guid catId, Guid provinceId)
        {
            DBAccess MyDB = new DBAccess();
            SqlDataReader MyReader = null;
            ArrayList List = new ArrayList();
            MyDB.DBOpen();
            MyDB.AddParameters(catId, "CATId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(provinceId, "RegionId", SqlDbType.UniqueIdentifier);
            string strSQL = "select CompanyId from TB_CompanyInfo where RegionId = @RegionId and CATId=@CATId";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            while (MyReader.Read())
            {
                Guid id = (Guid) MyReader[0];
                List.Add(id);
            }
            MyDB.DBClose();
            return (Guid[]) List.ToArray(typeof(Guid));
        }

        public static Guid GetCompanyIdViaCustomerId(Guid customerId)
        {
            SqlDataReader MyReader = null;
            Guid CompanyId = new Guid();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            string strSQL = "select CompanyId from TB_CustomerBasicInfo where CustomerId = @CustomerId";
            MyDB.AddParameters(customerId, "CustomerId", SqlDbType.UniqueIdentifier);
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            if (MyReader.Read())
            {
                CompanyId = MyReader.GetGuid(0);
            }
            MyDB.DBClose();
            return CompanyId;
        }

        public static int GetCustomerCountViaIdInCustomerBasicInfo(Guid userId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            string strSQL = "select count(*) from TB_CustomerBasicInfo where UserId = @UserId";
            MyDB.DBSetSelect(strSQL);
            int result = (int) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return result;
        }

        public static Guid[] GetCustomerIdListInCustomerBasicInfoViaUserId(Guid userId)
        {
            SqlDataReader MyReader = null;
            ArrayList List = new ArrayList();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            string strSQL = "select CustomerId from TB_CustomerBasicInfo where UserId=@UserId";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            while (MyReader.Read())
            {
                Guid id = (Guid) MyReader[0];
                List.Add(id);
            }
            MyDB.DBClose();
            return (Guid[]) List.ToArray(typeof(Guid));
        }

        public static string GetCustomerNameViaCustomerId(Guid customerId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(customerId, "CustomerId", SqlDbType.UniqueIdentifier);
            string strSQL = "select CustomerName from TB_CustomerBasicInfo where CustomerId = @CustomerId";
            MyDB.DBSetSelect(strSQL);
            object tmp = MyDB.DBExecuteScalar();
            MyDB.DBClose();
            if (tmp != null)
            {
                return tmp.ToString();
            }
            return "";
        }

        public static int GetCustomerUpdateNumInLog(Guid customerId, string year, string quarter)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(customerId, "CustomerId", SqlDbType.UniqueIdentifier);
            string monthStart = "";
            string monthEnd = "";
            string DateStart = "";
            string DateEnd = "";
            if (quarter == "1")
            {
                monthStart = "1";
                monthEnd = "3";
                DateStart = "1";
                DateEnd = "31";
            }
            else if (quarter == "2")
            {
                monthStart = "4";
                monthEnd = "6";
                DateStart = "1";
                DateEnd = "30";
            }
            else if (quarter == "3")
            {
                monthStart = "7";
                monthEnd = "9";
                DateStart = "1";
                DateEnd = "30";
            }
            else if (quarter == "4")
            {
                monthStart = "10";
                monthEnd = "12";
                DateStart = "1";
                DateEnd = "31";
            }
            StringBuilder sb = new StringBuilder();
            sb.Append("select count(*) from TB_SysLog where  OperateType like '%UpDate%' and CustomerId = @CustomerId and LogTime between '20");
            sb.Append(year);
            sb.Append("-");
            sb.Append(monthStart);
            sb.Append("-");
            sb.Append(DateStart);
            sb.Append(" 00:00:01' and '20");
            sb.Append(year);
            sb.Append("-");
            sb.Append(monthEnd);
            sb.Append("-");
            sb.Append(DateEnd);
            sb.Append(" 23:59:59'");
            string strSQL = sb.ToString();
            MyDB.DBSetSelect(strSQL);
            int result = (int) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return result;
        }

        public static int GetCustomerUpdateNumInLog(Guid customerId, string year, string quarter, Guid userId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(customerId, "CustomerId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            string monthStart = "";
            string monthEnd = "";
            string DateStart = "";
            string DateEnd = "";
            if (quarter == "1")
            {
                monthStart = "1";
                monthEnd = "3";
                DateStart = "1";
                DateEnd = "31";
            }
            else if (quarter == "2")
            {
                monthStart = "4";
                monthEnd = "6";
                DateStart = "1";
                DateEnd = "30";
            }
            else if (quarter == "3")
            {
                monthStart = "7";
                monthEnd = "9";
                DateStart = "1";
                DateEnd = "30";
            }
            else if (quarter == "4")
            {
                monthStart = "10";
                monthEnd = "12";
                DateStart = "1";
                DateEnd = "31";
            }
            StringBuilder sb = new StringBuilder();
            sb.Append("select count(*) from TB_SysLog where UserId=@UserId and OperateType like '%UpDate%' and CustomerId = @CustomerId and LogTime between '20");
            sb.Append(year);
            sb.Append("-");
            sb.Append(monthStart);
            sb.Append("-");
            sb.Append(DateStart);
            sb.Append(" 00:00:01' and '20");
            sb.Append(year);
            sb.Append("-");
            sb.Append(monthEnd);
            sb.Append("-");
            sb.Append(DateEnd);
            sb.Append(" 23:59:59'");
            string strSQL = sb.ToString();
            MyDB.DBSetSelect(strSQL);
            int result = (int) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return result;
        }

        public static Guid GetDirectoryIdViaProvinceId(Guid provinceId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(provinceId, "DirectoryProvince", SqlDbType.UniqueIdentifier);
            string strSQL = "select DirectoryId from TB_ResourceDirectory where DirectoryProvince = @DirectoryProvince";
            MyDB.DBSetSelect(strSQL);
            if (MyDB.DBExecuteScalar() == null)
            {
                MyDB.DBClose();
                return new Guid();
            }
            Guid tmp = (Guid) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return tmp;
        }

        public static int GetImportCustomerCountViaIdInOrgTree(Guid companyId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(companyId, "CompanyId", SqlDbType.UniqueIdentifier);
            string strSQL = "select count(*) from TB_CustomerOrgTree where CompanyId = @CompanyId";
            MyDB.DBSetSelect(strSQL);
            int result = (int) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return result;
        }

        public static DataSet GetKPI_Interface()
        {
            string strSQL = "Select TB_Region.RegionName,TB_KPI_Sys_Interface.* from TB_KPI_Sys_Interface left outer join TB_Region on TB_KPI_Sys_Interface.ProvinceId = TB_Region.RegionId";
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.DBSetSelect(strSQL);
            return MyDB.DBReturnDataSet();
        }

        public static KPI GetKPIViaUserId(Guid userId, string kpiLabel)
        {
            SqlDataReader MyReader = null;
            KPI kpi = new KPI();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            string strSQL = "select * from TB_KPI_Sys where UserId = @UserId and KPILabel = @KPILabel";
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(kpiLabel, "KPILabel", SqlDbType.VarChar);
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            if (MyReader.Read())
            {
                kpi.UserId = MyReader.GetGuid(0);
                kpi.FillInInfoCount = MyReader.GetDouble(1);
                kpi.FillInImportCustomerCount = MyReader.GetInt32(2);
                kpi.AllImportCustomerCount = MyReader.GetInt32(3);
                kpi.AllCustomerCount = MyReader.GetInt32(4);
                kpi.UpdateCount_Inspirit = MyReader.GetDouble(5);
                kpi.KPILabel = MyReader.GetString(6);
            }
            MyDB.DBClose();
            return kpi;
        }

        public static Guid GetProvinceIdViaCompanyId(Guid companyId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(companyId, "CompanyId", SqlDbType.UniqueIdentifier);
            string strSQL = "select RegionId from TB_CompanyInfo where CompanyId = @CompanyId";
            MyDB.DBSetSelect(strSQL);
            if (MyDB.DBExecuteScalar() == null)
            {
                MyDB.DBClose();
                return new Guid();
            }
            Guid tmp = (Guid) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return tmp;
        }

        public static int GetResourceCountViaProvinceId(Guid provinceId)
        {
            return 0;
        }

        public static int GetShareInfoCountInResourceInfo(Guid provinceId, string strProvinceField, string strTableName)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(provinceId, strProvinceField, SqlDbType.UniqueIdentifier);
            string strSQL = "select count(*) from " + strTableName + " where " + strProvinceField + " = @" + strProvinceField;
            MyDB.DBSetSelect(strSQL);
            int result = (int) MyDB.DBExecuteScalar();
            MyDB.DBClose();
            return result;
        }

        public static DataSet GetUser(Guid areaId, string strProvince, string strRole, string strQuarter)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(areaId, "AreaId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(strQuarter, "KPILabel", SqlDbType.VarChar);
            MyDB.AddParameters(new Guid(strProvince), "RegionId", SqlDbType.UniqueIdentifier);
            if (strRole != "All")
            {
                MyDB.AddParameters(new Guid(strRole), "RoleId", SqlDbType.UniqueIdentifier);
            }
            StringBuilder sb = new StringBuilder("");
            sb.Append("select TB_SysUser.LoginName,TB_KPI_Sys_Interface.* from dbo.TB_KPI_Sys_Interface left outer join TB_SysUser on TB_KPI_Sys_Interface.UserId = TB_SysUser.UserId ");
            sb.Append("     where                                                                 ");
            int posWhereExpressionStart = sb.ToString().Length;
            sb.Append("TB_KPI_Sys_Interface.UserId in                                                           ");
            sb.Append("( Select DISTINCT UserId from dbo.TB_UserArea where AreaId=@AreaId )   ");
            if (strProvince != "00000000-0000-0000-0000-000000000000")
            {
                sb.Append("and                                                                    ");
                sb.Append("TB_KPI_Sys_Interface.userId in                                                               ");
                sb.Append("(Select DISTINCT UserId from dbo.TB_UserRegion where RegionId=@RegionId)   ");
            }
            if (strRole != "All")
            {
                sb.Append("and                                                                    ");
                sb.Append("TB_SysUser.RoleId =@RoleId                                             ");
            }
            sb.Append("and TB_KPI_Sys_Interface.KPILabel=@KPILabel ");
            sb.Append("   order by  LoginName                                                     ");
            string strSQL = sb.ToString();
            MyDB.DBSetSelect(strSQL);
            return MyDB.DBReturnDataSet();
        }

        public static DataSet GetUser(Guid areaId, string strProvince, string strCat, string strRole, string strQuarter)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(areaId, "AreaId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(strQuarter, "KPILabel", SqlDbType.VarChar);
            MyDB.AddParameters(new Guid(strProvince), "RegionId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(new Guid(strCat), "CatId", SqlDbType.UniqueIdentifier);
            if (strRole != "All")
            {
                MyDB.AddParameters(new Guid(strRole), "RoleId", SqlDbType.UniqueIdentifier);
            }
            StringBuilder sb = new StringBuilder("");
            sb.Append("select TB_SysUser.LoginName,TB_KPI_Sys.* from dbo.TB_KPI_Sys left outer join TB_SysUser on TB_KPI_Sys.UserId = TB_SysUser.UserId ");
            sb.Append("     where                                                                 ");
            int posWhereExpressionStart = sb.ToString().Length;
            sb.Append("TB_KPI_Sys.UserId in                                                           ");
            sb.Append("( Select DISTINCT UserId from dbo.TB_UserArea where AreaId=@AreaId )   ");
            if (strProvince != "00000000-0000-0000-0000-000000000000")
            {
                sb.Append("and                                                                    ");
                sb.Append("TB_KPI_Sys.userId in                                                               ");
                sb.Append("(Select DISTINCT UserId from dbo.TB_UserRegion where RegionId=@RegionId)   ");
            }
            if (strCat != "00000000-0000-0000-0000-000000000000")
            {
                sb.Append("and                                                                     ");
                sb.Append("TB_KPI_Sys.userId in                                                              ");
                sb.Append("(Select DISTINCT UserId from dbo.TB_UserCAT where CatId=@CatId)            ");
            }
            if (strRole != "All")
            {
                sb.Append("and                                                                    ");
                sb.Append("TB_SysUser.RoleId =@RoleId                                             ");
            }
            sb.Append("and TB_KPI_Sys.KPILabel=@KPILabel ");
            sb.Append("   order by  LoginName                                                     ");
            string strSQL = sb.ToString();
            MyDB.DBSetSelect(strSQL);
            return MyDB.DBReturnDataSet();
        }

        public static Guid[] GetUserIdAryInKPI(string strProvinceId, string strCatId, Role[] roleAry, string strQuarter)
        {
            SqlDataReader MyReader = null;
            ArrayList List = new ArrayList();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(strQuarter, "KPILabel", SqlDbType.VarChar);
            MyDB.AddParameters(new Guid(strProvinceId), "RegionId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(new Guid(strCatId), "CatId", SqlDbType.UniqueIdentifier);
            StringBuilder sb = new StringBuilder("");
            sb.Append("select TB_KPI_Sys.userid from TB_KPI_Sys left outer join TB_SysUser on TB_KPI_Sys.userid = TB_SysUser.userid where ");
            sb.Append("TB_KPI_Sys.userid in (select userid from TB_UserArea where AreaId = '06BA8C26-B1C9-4415-A6EC-1CF5CE99BF15') ");
            sb.Append("and ");
            sb.Append("TB_KPI_Sys.userid in (select userid from TB_UserCAT where CatId = @CatId) ");
            sb.Append("and ");
            sb.Append("TB_KPI_Sys.userid in (select userid from TB_UserRegion where RegionId = @RegionId)");
            sb.Append("and TB_KPI_Sys.KPILabel=@KPILabel ");
            sb.Append(" and (");
            for (int i = 0; i < roleAry.Length; i++)
            {
                sb.Append(" TB_SysUser.RoleId = '" + roleAry[i].RoleId.ToString() + "'");
                sb.Append(" or");
            }
            string tmpStr = sb.ToString();
            string strSQL = tmpStr.Substring(0, tmpStr.Length - 2) + " ) order by  LoginName";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            while (MyReader.Read())
            {
                Guid id = (Guid) MyReader[0];
                List.Add(id);
            }
            MyDB.DBClose();
            return (Guid[]) List.ToArray(typeof(Guid));
        }

        public static Guid[] GetUserIdListInCompanyInfo()
        {
            SqlDataReader MyReader = null;
            ArrayList List = new ArrayList();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            string strSQL = "select DISTINCT UserId from TB_CompanyInfo";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            while (MyReader.Read())
            {
                try
                {
                    Guid id = (Guid) MyReader[0];
                    List.Add(id);
                    continue;
                }
                catch
                {
                    continue;
                }
            }
            MyDB.DBClose();
            return (Guid[]) List.ToArray(typeof(Guid));
        }

        public static Guid[] GetUserIdListInCustomerBasicInfo()
        {
            SqlDataReader MyReader = null;
            ArrayList List = new ArrayList();
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            string strSQL = "select DISTINCT UserId from TB_CustomerBasicInfo";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            while (MyReader.Read())
            {
                Guid id = (Guid) MyReader[0];
                List.Add(id);
            }
            MyDB.DBClose();
            return (Guid[]) List.ToArray(typeof(Guid));
        }

        public static void InsertACustomerIdInKPI(Guid userId, string label)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(label, "KPILabel", SqlDbType.VarChar);
            string strSQL = "Insert into TB_KPI_Sys (UserId,KPILabel) values (@UserId,@KPILabel)";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }

        public static void InsertACustomerIdInKPI_Interface(Guid provinceId, string label)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(provinceId, "ProvinceId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(label, "KPILabel", SqlDbType.VarChar);
            string strSQL = "Insert into TB_KPI_Sys_Interface (ProvinceId,KPILabel) values (@ProvinceId,@KPILabel)";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }

        public static void InsertACustomerIdInKPIMan(Guid userId, string label)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(label, "KPILabel", SqlDbType.VarChar);
            string strSQL = "Insert into TB_KPI_Man (UserId,KPILabel) values (@UserId,@KPILabel)";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }

        public static bool IsExistCustomerPreferenceInfoViaId(Guid id)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(id, "CustomerId", SqlDbType.UniqueIdentifier);
            string strSQL = "select * from TB_CustomerPreference where CustomerId = @CustomerId";
            MyDB.DBSetSelect(strSQL);
            if (MyDB.DBExecuteScalar() == null)
            {
                MyDB.DBClose();
                return false;
            }
            MyDB.DBClose();
            return true;
        }

        public static bool IsExistImportCustomerInKPI(Guid companyId, string customerName)
        {
            SqlDataReader MyReader = null;
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(companyId, "CompanyId", SqlDbType.UniqueIdentifier);
            string strSQL = "select NodeName from TB_CustomerOrgTree where CompanyId = @CompanyId";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteReader();
            MyReader = MyDB.DBReader;
            bool result = false;
            while (MyReader.Read())
            {
                if (MyReader.GetString(0) == customerName)
                {
                    result = true;
                    MyDB.DBClose();
                    return result;
                }
            }
            MyDB.DBClose();
            return result;
        }

        public static bool IsExistOrgStructInCompanyInfo(Guid companyId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(companyId, "CompanyId", SqlDbType.UniqueIdentifier);
            string strSQL = "select * from TB_CustomerOrgTree where CompanyId = @CompanyId";
            MyDB.DBSetSelect(strSQL);
            if (MyDB.DBExecuteScalar() == null)
            {
                MyDB.DBClose();
                return false;
            }
            MyDB.DBClose();
            return true;
        }

        public static bool IsExistUploadInfoInFileStorageInfoViaDirectoryId(Guid directoryId)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(directoryId, "DirectoryId", SqlDbType.UniqueIdentifier);
            string strSQL = "select * from TB_FileStorageInfo where DirectoryId = @DirectoryId";
            MyDB.DBSetSelect(strSQL);
            if (MyDB.DBExecuteScalar() == null)
            {
                MyDB.DBClose();
                return false;
            }
            MyDB.DBClose();
            return true;
        }

        public static bool IsExistYQInKPI(string strYQ)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(strYQ, "KPILabel", SqlDbType.VarChar);
            string strSQL = "select * from TB_KPI_Sys where KPILabel = @KPILabel";
            MyDB.DBSetSelect(strSQL);
            if (MyDB.DBExecuteScalar() == null)
            {
                MyDB.DBClose();
                return false;
            }
            MyDB.DBClose();
            return true;
        }

        public static void RemoveUserIdInKPI(string label)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(label, "KPILabel", SqlDbType.VarChar);
            string strSQL = "Delete From TB_KPI_Sys where KPILabel = @KPILabel ";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }

        public static void RemoveUserIdInKPI_Interface(string label)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(label, "KPILabel", SqlDbType.VarChar);
            string strSQL = "Delete From TB_KPI_Sys_Interface where KPILabel = @KPILabel ";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }

        public static KPI SumKPIWithATeam(KPI[] kpiAry)
        {
            KPI resultKPI = new KPI();
            Guid userId = new Guid();
            double fillInInfoCount = 0.0;
            int fillInImportCustomerCount = 0;
            int allImportCustomerCount = 0;
            int allCustomerCount = 0;
            double updateCount_Inspirit = 0.0;
            string kPILabel = "";
            int allInfoCount = 0;
            for (int i = 0; i < kpiAry.Length; i++)
            {
                fillInInfoCount += kpiAry[i].FillInInfoCount;
                fillInImportCustomerCount += kpiAry[i].FillInImportCustomerCount;
                allImportCustomerCount += kpiAry[i].AllImportCustomerCount;
                allCustomerCount += kpiAry[i].AllCustomerCount;
                updateCount_Inspirit += kpiAry[i].UpdateCount_Inspirit;
                allInfoCount += kpiAry[i].AllCustomerCount * 0x23;
            }
            resultKPI.UserId = userId;
            resultKPI.FillInInfoCount = fillInInfoCount;
            resultKPI.FillInImportCustomerCount = fillInImportCustomerCount;
            resultKPI.AllImportCustomerCount = allImportCustomerCount;
            resultKPI.AllCustomerCount = allCustomerCount;
            resultKPI.UpdateCount_Inspirit = updateCount_Inspirit;
            resultKPI.KPILabel = kPILabel;
            resultKPI.AllInfoCount = allInfoCount;
            return resultKPI;
        }

        public static void UpdateUserKPI(Guid userId, string lable, double importInfo, int fillInImportCustomerCountNum, int allImportCustomerCountNum, int allCustomerCountNum, double updateCount)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(importInfo, "FillInInfoCount", SqlDbType.Float);
            MyDB.AddParameters(fillInImportCustomerCountNum, "FillInImportCustomerCount", SqlDbType.Int);
            MyDB.AddParameters(allImportCustomerCountNum, "AllImportCustomerCount", SqlDbType.Int);
            MyDB.AddParameters(allCustomerCountNum, "AllCustomerCount", SqlDbType.Int);
            MyDB.AddParameters(userId, "UserId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(lable, "KPILabel", SqlDbType.VarChar);
            MyDB.AddParameters(updateCount, "UpdateCount_Inspirit", SqlDbType.Float);
            string strSQL = "Update TB_KPI_Sys set FillInInfoCount = @FillInInfoCount,FillInImportCustomerCount=@FillInImportCustomerCount,AllImportCustomerCount=@AllImportCustomerCount,AllCustomerCount=@AllCustomerCount,UpdateCount_Inspirit=@UpdateCount_Inspirit where UserId = @UserId and KPILabel=@KPILabel";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }

        public static void UpdateUserKPI_Interface(Guid provinceId, string lable, double fillInInfoCount, int fillInCompanyCount, int isUploadCompanyAddList, int fillInShareCount)
        {
            DBAccess MyDB = new DBAccess();
            MyDB.DBOpen();
            MyDB.AddParameters(fillInInfoCount, "FillInInfoCount", SqlDbType.Float);
            MyDB.AddParameters(fillInCompanyCount, "FillInCompanyCount", SqlDbType.Int);
            MyDB.AddParameters(isUploadCompanyAddList, "IsUploadCompanyAddList", SqlDbType.Int);
            MyDB.AddParameters(fillInShareCount, "FillInShareCount", SqlDbType.Int);
            MyDB.AddParameters(provinceId, "ProvinceId", SqlDbType.UniqueIdentifier);
            MyDB.AddParameters(lable, "KPILabel", SqlDbType.VarChar);
            string strSQL = "Update TB_KPI_Sys_Interface set FillInInfoCount = @FillInInfoCount,FillInCompanyCount=@FillInCompanyCount,IsUploadCompanyAddList=@IsUploadCompanyAddList,FillInShareCount=@FillInShareCount where ProvinceId = @ProvinceId and KPILabel=@KPILabel";
            MyDB.DBSetSelect(strSQL);
            MyDB.DBExcuteNonQuery();
            MyDB.DBClose();
        }
    }
}

